| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkMemory::BufferCast< T > Class Template Reference

Holds a Buffer and make it easy to cast the binary data. More...

## Public Member Functions
| BufferCast () noexcept=default
| BufferCast (unsigned long long size) noexcept
| BufferCast (T *data, unsigned long long size) noexcept
| BufferCast (const Buffer &buffer) noexcept
| BufferCast (Buffer &&buffer) noexcept
| BufferCast (const BufferCast &cast) noexcept
| BufferCast (BufferCast &&cast) noexcept
template<typename U = T>
| BufferCast (std::enable_if_t<!std::is_class_v< U >, const Buffer & > buffer) noexcept
| ~BufferCast ()
T * | getData () const
unsigned long long | getSize () const
bool | empty () const
T & | front ()
const T & | front () const
T & | back ()
const T & | back () const
T * | begin ()
const T * | begin () const
T * | end ()
const T * | end () const
BufferCast< T > & | clear ()
BufferCast< T > & | resize (unsigned long long size)
T & | append (const T &value)
template<typename U = T>
std::enable_if_t< std::is_class_v< U >, T & > | append (T &&value)
BufferCast< T > & | erase (unsigned long long index, unsigned long long count=1ull) Buffer relinquishBufferOwnership()
BufferCastDataDescriptor< T > | relinquishDataOwnership ()
T & | operator[] (unsigned long long index)
const T & | operator[] (unsigned long long index) const
BufferCast< T > & | operator= (const BufferCast< T > &other) noexcept
template<typename U = T>
std::enable_if_t<!std::is_class_v< U >||std::is_move_assignable_v< U >, BufferCast< T > & > | operator= (BufferCast< T > &&other) noexcept
template<std::size_t S>
| BufferCast (const std::array< T, S > &array) noexcept
template<typename U , std::size_t S>
| BufferCast (const std::array< U, S > &array) noexcept
| BufferCast (const std::vector< T > &vec) noexcept
template<typename U >
| BufferCast (const std::vector< U > &vec) noexcept
| BufferCast (std::initializer_list< T > args) noexcept
| BufferCast (std::initializer_list< U > args) noexcept

## Detailed Description

### template<typename T = unsigned char>
class nkMemory::BufferCast< T >

Holds a Buffer and make it easy to cast the binary data.

This class holds a binary Buffer and abstracts all casting needed when using a buffer to keep data that can be interpreted. This buffer cast owns the buffer, meaning that it also owns the memory allocated.

If you need a simple non-owning view over the data, consider looking at BufferView.

## Constructor & Destructor Documentation

## ◆ BufferCast() [1/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( |  | ) |
| default noexcept

Default constructor. The buffer will be empty.

## ◆ BufferCast() [2/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | unsigned long long | size | ) |
| noexcept

Size constructor. Will allocate the size requested within the buffer. Memory will be 0-cleared.

Parameters

  size | The size of the buffer to create, in number of elements.

## ◆ BufferCast() [3/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | T * | data,
|  | unsigned long long | size
| ) |  |
| noexcept

Data constructor. Will copy the data into its internal memory.

Parameters

  data | Pointer to the data to copy.
  size | The size of the data to copy, in number of elements.

## ◆ BufferCast() [4/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | const Buffer & | buffer | ) |
| noexcept

Copy buffer constructor. Will duplicate the data.

Parameters

  buffer | The buffer to copy.

## ◆ BufferCast() [5/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | Buffer && | buffer | ) |
| noexcept

Move buffer constructor. Data will be moved into the buffer being constructed.

Parameters

  buffer | The buffer to move.

## ◆ BufferCast() [6/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | const BufferCast< T > & | cast | ) |
| noexcept

Copy cast constructor. Will duplicate the data.

Parameters

  cast | The cast to copy.

## ◆ BufferCast() [7/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | BufferCast< T > && | cast | ) |
| noexcept

Move cast constructor. Data will be moved into the cast being constructed.

Parameters

  cast | The cast to move.

## ◆ BufferCast() [8/14]

template<typename T = unsigned char>
template<typename U = T>

nkMemory::BufferCast< T >::BufferCast | ( | std::enable_if_t<!std::is_class_v< U >, const Buffer & > | buffer | ) |
| noexcept

Binary data copy constructor.

Parameters

  buffer | The buffer to copy and reinterpret the binary data from.

Remarks
  This constructor is only available if the contained typename is not a class.

## ◆ ~BufferCast()

template<typename T = unsigned char>

nkMemory::BufferCast< T >::~BufferCast | ( |  | ) |

Destructor. The destructor frees the memory, invalidating all potential pointers to it. If T is a class needing destruction, then the destructor of each entry will get called.

## ◆ BufferCast() [9/14]

template<typename T = unsigned char>
template<std::size_t S>

nkMemory::BufferCast< T >::BufferCast | ( | const std::array< T, S > & | array | ) |
| noexcept

Utility copy constructor with arrays.

Parameters

  array | The array to copy from.

## ◆ BufferCast() [10/14]

template<typename T = unsigned char>
template<typename U , std::size_t S>

nkMemory::BufferCast< T >::BufferCast | ( | const std::array< U, S > & | array | ) |
| noexcept

Utility copy constructor with arrays, which memory will be reinterpreted to another type.

Parameters

  array | The array to copy from.

## ◆ BufferCast() [11/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | const std::vector< T > & | vec | ) |
| noexcept

Utility copy constructor with vectors.

Parameters

  vec | The vector to copy from.

## ◆ BufferCast() [12/14]

template<typename T = unsigned char>
template<typename U >

nkMemory::BufferCast< T >::BufferCast | ( | const std::vector< U > & | vec | ) |
| noexcept

Utility copy constructor with vectors, which memory will be reinterpreted to another type.

Parameters

  vec | The vector to copy from.

## ◆ BufferCast() [13/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | std::initializer_list< T > | args | ) |
| noexcept

Utility initializer list constructor.

Parameters

  args | The list of elements to initialize the buffer with.

## ◆ BufferCast() [14/14]

template<typename T = unsigned char>

nkMemory::BufferCast< T >::BufferCast | ( | std::initializer_list< U > | args | ) |
| noexcept

Utility initializer list constructor, which memory entries will get converted.

Parameters

  args | The list of elements to initialize the buffer with.

## Member Function Documentation

## ◆ getData()

template<typename T = unsigned char>

T* nkMemory::BufferCast< T >::getData | ( |  | ) | const

Returns
  The pointer over the internal data.

## ◆ getSize()

template<typename T = unsigned char>

unsigned long long nkMemory::BufferCast< T >::getSize | ( |  | ) | const

Returns
  The size of the buffer, in number of elements.

## ◆ empty()

template<typename T = unsigned char>

bool nkMemory::BufferCast< T >::empty | ( |  | ) | const

Returns
  Whether the buffer is empty (true) or not (false). An empty buffer has a size of 0.

## ◆ front() [1/2]

template<typename T = unsigned char>

T& nkMemory::BufferCast< T >::front | ( |  | ) |

Returns
  A reference over the first element of the buffer.

## ◆ front() [2/2]

template<typename T = unsigned char>

const T& nkMemory::BufferCast< T >::front | ( |  | ) | const

Returns
  A reference over the first element of the buffer.

## ◆ back() [1/2]

template<typename T = unsigned char>

T& nkMemory::BufferCast< T >::back | ( |  | ) |

Returns
  A reference over the last element of the buffer.

## ◆ back() [2/2]

template<typename T = unsigned char>

const T& nkMemory::BufferCast< T >::back | ( |  | ) | const

Returns
  A reference over the last element of the buffer.

## ◆ begin() [1/2]

template<typename T = unsigned char>

T* nkMemory::BufferCast< T >::begin | ( |  | ) |

Returns
  A pointer over the beginning of the memory spot.

## ◆ begin() [2/2]

template<typename T = unsigned char>

const T* nkMemory::BufferCast< T >::begin | ( |  | ) | const

Returns
  A pointer over the beginning of the memory spot.

## ◆ end() [1/2]

template<typename T = unsigned char>

T* nkMemory::BufferCast< T >::end | ( |  | ) |

Returns
  A pointer right past the end of the memory spot.

## ◆ end() [2/2]

template<typename T = unsigned char>

const T* nkMemory::BufferCast< T >::end | ( |  | ) | const

Returns
  A pointer right past the end of the memory spot.

## ◆ clear()

template<typename T = unsigned char>

BufferCast<T>& nkMemory::BufferCast< T >::clear | ( |  | ) |

Clears the buffer, freeing its internal memory and resetting it to its empty state.

## ◆ resize()

template<typename T = unsigned char>

BufferCast<T>& nkMemory::BufferCast< T >::resize | ( | unsigned long long | size | ) |

Resizes the buffer for it to fit a given size. This will trigger a reallocation of the data. In the process, the buffer will copy its content to the new memory area.

Parameters

  size | The size to fit, in number of elements.

## ◆ append() [1/2]

template<typename T = unsigned char>

T& nkMemory::BufferCast< T >::append | ( | const T & | value | ) |

Appends an element to the buffer. This will cause the buffer to reallocate and copy data around.

Parameters

  value | The value to append.

Returns
  The reference over the element appended in the buffer.

## ◆ append() [2/2]

template<typename T = unsigned char>
template<typename U = T>

std::enable_if_t<std::is_class_v<U>, T&> nkMemory::BufferCast< T >::append | ( | T && | value | ) |

Appends an element to the buffer by moving it in. This will cause the buffer to reallocate and copy data around.

Parameters

  value | The value to append.

Returns
  The reference over the element appended in the buffer.

## ◆ erase()

template<typename T = unsigned char>

BufferCast<T>& nkMemory::BufferCast< T >::erase | ( | unsigned long long | index,
|  | unsigned long long | count = `1ull`
| ) |  |

Erases a number of elements from the container.

Parameters

  index | The index at which the erasure should start.
  count | The number of elements to erase.

Returns
  A reference over the container. Forwards the internal buffer's ownership and memory.
  A buffer in which the internal memory buffer has been moved.

Remarks
  This causes no copy to occur, as memory is forwarded. However, the internal memory of the BufferCast will be reinitialized. The method is only enabled for types that are not class, or trivially destructible.

## ◆ relinquishDataOwnership()

template<typename T = unsigned char>

BufferCastDataDescriptor<T> nkMemory::BufferCast< T >::relinquishDataOwnership | ( |  | ) |

Forwards the internal buffer's data ownership and memory.

Returns
  The internal buffer's memory descriptor.

Remarks
  See Buffer::relinquishDataOwnership for the implications of this operation. The internal memory of the BufferCast will be reinitialized.

## ◆ operator[]() [1/2]

template<typename T = unsigned char>

T& nkMemory::BufferCast< T >::operator[] | ( | unsigned long long | index | ) |

Indexing operator.

Parameters

  index | The index of the element to index in the memory.

Returns
  A reference over requested element.

## ◆ operator[]() [2/2]

template<typename T = unsigned char>

const T& nkMemory::BufferCast< T >::operator[] | ( | unsigned long long | index | ) | const

Indexing operator, const versioned.

Parameters

  index | The index of the element to index in the memory.

Returns
  A reference over requested element.

## ◆ operator=() [1/2]

template<typename T = unsigned char>

BufferCast<T>& nkMemory::BufferCast< T >::operator= | ( | const BufferCast< T > & | other | ) |
| noexcept

Copy assignment operator.

Parameters

  other | The other buffer to copy from.

Returns
  The calling instance.

## ◆ operator=() [2/2]

template<typename T = unsigned char>
template<typename U = T>

std::enable_if_t<!std::is_class_v<U> || std::is_move_assignable_v<U>, BufferCast<T>&> nkMemory::BufferCast< T >::operator= | ( | BufferCast< T > && | other | ) |
| noexcept

Move assignment operator.

Parameters

  other | The other buffer to move from.

Returns
  The calling instance.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsMemory/Containers/BufferCast.h